<template>
    <div>
        <el-card class="box-card" shadow="never">
            <!--导航栏-->
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item>系统设置</el-breadcrumb-item>
                 <el-breadcrumb-item>我要办事</el-breadcrumb-item>
            </el-breadcrumb>
            <el-form ref="form" class="edit-el-form"  :model="form" label-width="auto">
                <el-form-item label="组织关系转接" prop="work_relation">
                  <Editor :catchData="catchWorkRelationData" :child_content="work_relation_content"></Editor>
                </el-form-item>
                <el-form-item label="缴纳党费" prop="work_df">
                  <Editor :catchData="catchWorkDfData" :child_content="work_df_content"></Editor>
                </el-form-item>
                <el-form-item label="申请低保" prop="work_db">
                  <Editor :catchData="catchWorkDbData" :child_content="work_db_content"></Editor>
                </el-form-item>
                <el-form-item label="申请补贴" prop="work_bt">
                  <Editor :catchData="catchWorkBtData" :child_content="work_bt_content"></Editor>
                </el-form-item>
                <el-form-item label="办理证件" prop="work_zj">
                  <Editor :catchData="catchWorkZjData" :child_content="work_zj_content"></Editor>
                </el-form-item>
                <el-form-item label="我要参军" prop="work_cj">
                  <Editor :catchData="catchWorkCjData" :child_content="work_cj_content"></Editor>
                </el-form-item>
                <!--查看不展示按钮-->
                <el-form-item>
                    <el-button type="primary" @click="submitForm('form')" :loading="loading">{{button_name}}</el-button>
                </el-form-item>
            </el-form>
        </el-card>

    </div>
</template>

<script>
    import { getWorkInfo,editWork } from '@/api/work.js'
    import Editor from '@/components/Editor.vue';
    export default {
        name:'WorkSetting',
        components:{Editor},
        inject:['reload'],
        data() {
            return {
                form: {
                    work_relation:'',
                    work_df:'',
                    work_db:'',
                    work_bt:'',
                    work_zj:'',
                    work_cj:''
                },
                //加载组件
                loading: false,
                button_name:'立即提交',
                content:'我要办事设置',
                work_relation_content:'',
                work_df_content:'',
                work_db_content:'',
                work_bt_content:'',
                work_zj_content:'',
                work_cj_content:''
            }
        },
        methods: {
            submitForm(formName){
                //判断内容不为空
                if(this.form.work_relation==undefined){
                    this.$message({
                        message:'请输入组织关系转接',
                        type:'error',
                        duration:1000,
                    });
                    return false;
                };
                this.loading=true;
                this.button_name='正在提交';
                let send_data={
                    api_token:this.$store.getters.getSessionId,
                    work_relation:this.form.work_relation,
                    work_df:this.form.work_df,
                    work_db:this.form.work_db,
                    work_bt:this.form.work_bt,
                    work_zj:this.form.work_zj,
                    work_cj:this.form.work_cj
                };
                if(this.id!=-1){
                    send_data.id=this.id;
                }
                let that=this;
                editWork(send_data).then(function(response){
                    let code=response.data.code;
                     let type=code==1?'success':'error';
                     let msg=code==1?'成功':'失败';
                     that.$message({
                         message:that.content+msg,
                         duration:1200,
                         type:type,
                         onClose:function(e){
                             that.loading=false;
                             if(code==1){
                                that.$router.push('/worksetting');
                             }else{
                                that.button_name='立即提交';
                             }
                         }
                    })
                })
            },
            back(){
                this.$router.go(-1);
            },
            //富文本内容
            catchWorkRelationData(e){
               this.form.work_relation=e;
            },
            catchWorkDfData(e){
               this.form.work_df=e;
            },
            catchWorkDbData(e){
               this.form.work_db=e;
            },
            catchWorkBtData(e){
               this.form.work_bt=e;
            },
            catchWorkZjData(e){
               this.form.work_zj=e;
            },
            catchWorkCjData(e){
               this.form.work_cj=e;
            }
        },
        created(){
            //查询记录
            var send_data={
                api_token:this.$store.getters.getSessionId,
            }
            let that=this;
            getWorkInfo(send_data).then(function(response){
                if(response.data.code==1){
                  let val=response.data.info;
                  that.form.work_relation=val.work_relation;
                  that.form.work_df=val.work_df;
                  that.form.work_db=val.work_db;
                  that.form.work_bt=val.work_bt;
                  that.form.work_zj=val.work_zj;
                  that.form.work_cj=val.work_cj;
                  that.work_relation_content=val.work_relation;
                  that.work_df_content=val.work_df;
                  that.work_db_content=val.work_db;
                  that.work_bt_content=val.work_bt;
                  that.work_zj_content=val.work_zj;
                  that.work_cj_content=val.work_cj;
                }
            })
        },
        computed:{
            id(){
                return this.$route.params.id;
            }
        }
    }
</script>

<style>
    .edit-el-form{
        margin-top:30px;
    }
</style>
